@extends('backstage.layout.master')
@section('title', '产品模板定制区域颜色默认列表')
@section('style')
    <style>
        .colour_image{
            width: 300px;
        }
        .colour_image img{
            width: 100px;
            height: 100px;
        }
        th{
            text-align: center;
        }
        td{
            text-align: center;
        }
        .action-box{
            width: 200px;
        }
    </style>
@stop
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a target="_blank" href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a target="_blank" href="/backstage/product-temp/product-temp-list">产品模板</a>
            </li>
            <li>
                产品模板定制区域颜色默认列表
            </li>
        </ul><!-- .breadcrumb -->
    </div>

    <div class="page-content">
        <div class="page-header">
            <h1>
                产品模板
                <small>
                    <i class="icon-double-angle-right"></i>
                </small>
                <span class="pull-right">
                <button class="btn btn-primary" onclick="javascript:window.location.href='{{asset('')}}backstage/product-temp/product-temp-list'">返回产品模板列表</button>
                </span>
            </h1>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <h3 class="header smaller lighter red">简介：</h3>
                <div class="well">
                    <h4 class="green smaller lighter"></h4>
                    列表中颜色，将在模板添加工艺后，作为默认文本可供选择颜色
                </div>
            </div>
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="alert alert-info">
                    <i class="icon-hand-right"></i>
                    可定制颜色添加:&nbsp
                    <select id="">
                        <option selected value="sel_colour">颜色</option>
                    </select>
                    <select id="sel_colour">
                        @if(sizeof($un_sel_colours)==0)
                            暂无可选颜色~~~~~~
                        @else
                         @foreach($un_sel_colours as $un_sel_colour)
                        <option value={{isset($un_sel_colour->colour_id)?$un_sel_colour->colour_id:0}}>{{isset($un_sel_colour->colour_name)?$un_sel_colour->colour_name:''}}</option>
                         @endforeach
                        @endif
                    </select>
                    <button onclick="addCaftsmanshipDefaultColour()">添加</button>
                </div>
                <div class="table-responsive">
                    <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th class="center">
                                <label>
                                    <input type="checkbox" class="ace">
                                    <span class="lbl"></span>
                                </label>
                            </th>
                            <th>编号</th>
                            <th>颜色编号</th>
                            <th>颜色名</th>
                            <th>十六进制色值</th>
                            <th>色块</th>
                            <th>操作</th>
                        </tr>
                        </thead>

                        <tbody>
                        @foreach ($default_colours as $default_colour)
                            <tr class="" data-tr-id="{{$default_colour->id}}">
                                <td class="center">
                                    <label>
                                        <input type="checkbox" class="ace">
                                        <span class="lbl"></span>
                                    </label>
                                </td>
                                <td>{{isset($default_colour->id)?$default_colour->id:''}}</td>
                                <td>{{isset($default_colour->colour_id)?$default_colour->colour_id:''}}</td>
                                <td>
                                    {{isset($default_colour->colour_name)?$default_colour->colour_name:''}}
                                </td>
                                <td>
                                    {{isset($default_colour->colour_code)?$default_colour->colour_code:''}}
                                </td>
                                <td class="colour_image">
                                    <img src="{{isset($default_colour->colour_image)?$default_colour->colour_image:''}}">
                                </td>
                                <td class="center action-box" >
                                <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                                    <a  title="删除" style="color:#d77600;cursor: pointer;" onclick="deleteCraftsmanshipDefaultColor('{{isset($default_colour->colour_id)?$default_colour->colour_id:0}}','{{isset($default_colour->id)?$default_colour->id:0}}')">
                                        <i class="icon-trash bigger-130"></i>
                                    </a>
                                </div>
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="dataTables_info" id="sample-table-2_info"></div>
                    </div>
                    <div class="col-sm-6">
                        <div class="dataTables_paginate paging_bootstrap">
                            <?php echo $default_colours->render(); ?>
                        </div>
                    </div>
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script type="text/javascript">
        $(function () {
            $('[data-rel=tooltip]').tooltip();
            $('table th input:checkbox').on('click' , function(){
                var that = this;
                $(this).closest('table').find('tr > td:first-child input:checkbox')
                        .each(function(){
                            this.checked = that.checked;
                            $(this).closest('tr').toggleClass('selected');
                        });

            });
        });
        /**
         * 删除制作工艺下默认颜色列表下颜色
         * */
        function deleteCraftsmanshipDefaultColor(colour_id,id) {
            if(colour_id==0){
                swal('获取ID出错','','warning');
                return false;
            }
            swal({
                title: "确定删除？",
                text: "",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: true,
                closeOnCancel: true
            },function (){
                $.ajax({
                    type: "post",
                    url: "/backstage/product-temp/delete-craftsmanship-default-colour",
                    data:{"colour_id":colour_id},
                    dataType: 'json',
                    success: function(res){
                        if(res.state==1){
                            swal({
                                title:'删除成功！',
                                text: "",
                                type: "success",
                                timer:2000
                            });
                            $('[data-tr-id='+id+']').remove();
                        }else{
                            swal({
                                title: res.message,
                                text: "",
                                type: "error",
                                timer:3000
                            });
                        }
                    },
                    error:function(){
                        swal({
                            title: "系统繁忙！",
                            text: "",
                            type: "error",
                            timer:2000
                        });
                    }
                });//ajax
            });
        }
        var state = 0;
        function addCaftsmanshipDefaultColour(){
            if(state == 0){
                state = 1;
                var colour_id = $("#sel_colour option:selected").val();
                console.log('colour_id:'+colour_id);
                if((colour_id==0)){
                    swal('系统繁忙稍后再试','','warning');
                    state = 0;
                    return ;
                }
                swal('处理中，请稍后','','warning');
                $.ajax({
                    type: "post",
                    url: "/backstage/product-temp/add-craftsmanship-default-colour",
                    data:{"colour_id":colour_id},
                    dataType: 'json',
                    success: function(res){
                        if(res.state ==1){
                            swal('添加成功','','success');
                            setTimeout(function(){},1000);
                            location.reload();
                            return ;
                        }
                        swal(res.message,'','warning');
                    },
                    error:function(){
                        swal('系统繁忙','请稍后重试','warning');
                    }
                });
                state = 0;
            }

        }
        /***
         * 检查数据格式
         * @param input
         * @returns {boolean}
         */
        function checkRate(input)
        {
            var reg = new RegExp("^[0-9]{1,3}$");
            return reg.test(input);
        }
    </script>
@stop